package com.codeoss.framework.impexp;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.data.metadata.Table;

@Service
public class ImportManager implements ApplicationContextAware{
	private ApplicationContext applicationContext;
	
	@Transactional
	public Map<String, Object> importProperties(YunContext yunContext,Table table,InputStream is)throws IOException{
		IPropertiesImport propertiesImport=applicationContext.getBean(IPropertiesImport.class);
		return propertiesImport.importProperties(yunContext, table, is);
	}
	
	@Transactional
	public void importExcel(YunContext yunContext,Table table,InputStream is)throws IOException{
		IExcelImport excelImport=applicationContext.getBean(IExcelImport.class);
		excelImport.importExcel(yunContext, table, is);
	}
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		// TODO Auto-generated method stub
		this.applicationContext=applicationContext;
	}
}
